package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Log;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.entity.User;
import com.atguigu.jxc.entity.UserLogin;
import com.atguigu.jxc.service.LogService;
import com.atguigu.jxc.service.SupplierService;
import com.atguigu.jxc.service.UserService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.Map;

/**
 * @description 供应商信息Controller控制器
 */
@Controller
@RequestMapping("/supplier")
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 分页查询供应商
     * @param  page（当前页数）
     * @param rows（每页显示的记录数）
     * @param supplierName（模糊查询条件）
     * @return 登录结果JSON
     */
    @ResponseBody
    @PostMapping("/list")
    public Map<String,Object> listSupplier(Integer page,Integer rows,String supplierName){
        return supplierService.getSupplierList(page,rows,supplierName);
    }

    @ResponseBody
   // @PostMapping("/save")
    @RequestMapping(value = "/save")
    public ServiceVO saveOrUpdateSupplier(String supplierId, Supplier supplier){
        ServiceVO serviceVO=new ServiceVO(SuccessCode.SUCCESS_CODE,SuccessCode.SUCCESS_MESS,null);
        supplierService.save(supplier);
        return serviceVO;
    }

    @ResponseBody
    //批量删除供应商
    @PostMapping("/delete")
    public ServiceVO delete(String  ids){
        return supplierService.delete(ids);
    }
}
